#pragma once

#include "ofMain.h"
#include "ball.h"
#include "flyingBall.h"
#include "captureCameraManager.h"
#include "ptclRecvData.h"
#include "ptclSendData.h"
#include "ofxDaito.h"
#include "baseScene.h"
#include "simplePattern.h"
#include "whitenoiseScene.h"
#include "sinwaveScene.h"
#include "blinkScene.h"
#include "perlinnoiseScene.h"
#include "triangleScene.h"
#include "onlyCheckPointsAndCenterScene.h"
#include "vectorLinesScene.h"
#include "quadricCurveScene.h"
#include "gradientScene.h"
#include "debugScene.h"
#include "checkPoint.h"
#include "realBall.h"
#include "checkPatternScene.h"
#include "dotsAndLineScene.h"
#include "distanceScene.h"
#include "checkPatternScene.h"
#include "colorTestScene.h"
#include "ofxOsc.h"
#include "colorTestScene.h"
#include "crossScene.h"

#define USE_SERIAL 

#define PORT 8898
#define TIME_IN_MS_BETWEEN_CHECKPOINTS 5500
#define ENABLE_SPIRAL
#define ENABLE_DEBUG
#define WIDTH_CAMERA 320
#define HEIGHT_CAMERA 240
#define PREVIEWRATIO 4
#define ENABLE_INFINITY_BALL
#define NUM_BALLS 200
//#define ENABLE_SEND_OSC // <<< for debug	


//#include "ofxVectorMath.h"
//- for 007
//#define LENGTH_RAIL 280000
//#define NUM_CHECKPOINTS 16
//#define LENGTH_BALL 70

enum  {
	SHOW_SIMULATOR, SHOW_REALTIME, SHOW_NUM
};

enum  {
	GATE_CLOSE, GATE_OPEN, GATE_PULSE,GATE_NUM
};

enum  {
	MODE_CONTROL, MODE_WHOLE
};

enum  {
	PIXELS_SIMPLE, PIXELS_SIMPLE_NOISE, PIXELS_SINWAVE, PIXELS_BLINK, PIXELS_PERLIN_NOISE, PIXELS_NUM
};

static string pixelsStr[] = {
	"PIXELS_WHITE_NOISE", "PIXELS_PERLIN_NOISE", "PIXELS_CAMERA", "PIXELS_CHECK", "PIXELS_GRADIENT", "PIXELS_MOVING_LINE"
};

//id 253
class testApp : public ofBaseApp{

public:
	void setup();
	void update();
	void draw();
	void putNewBall();

	void keyPressed  (int key);
	void keyReleased(int key);
	void mouseMoved(int x, int y );
	void mouseDragged(int x, int y, int button);
	void mousePressed(int x, int y, int button);
	void mouseReleased(int x, int y, int button);
	void windowResized(int w, int h);
	
	void alternatePixels(unsigned char * _srcPixels, unsigned char * _destinationPixels);
	
	int numUnits; //チェックポイント間の分割数
	int count;
	int widthUnit;
	ofVec2f pos;
	ofVec2f posOffset;
	vector<ball>balls;
	vector<flyingBall> flyingBalls;
	vector<checkPoint*> checkPoints;
	vector<realBall*> realBalls;
	vector<flyingBall> realFlyingBalls;
//	captureCameraManager * CM;
//	patternGenerator * PG;
	int numBall;
	int counterBall;
	int frames;
	int widthSpiralPreview, heightSpiralPreview;

	void nextPattern();
	void prevPattern();
	void gotoPattern(int thePattern);
	void doOSC();
	
	//serial
#ifdef USE_SERIAL
	ofSerial serial;
	ptclSendData sendThreadObj;
	ptclRecvData recvThreadObj;
#endif

#ifdef ENABLE_DEBUG
	ofxCvGrayscaleImage grayDebug;
	ofxCvColorImage colorDebug;	
#endif	
	unsigned char * pixelData;
	unsigned char * pixelColorData;
	unsigned char * currentGrayPixels;
	unsigned char * currentColorPixels;
	unsigned char * currentBallColorPixels;
	int currentPattern;
	int numPatterns;
	int currentShowing;

	basePattern ** patterns;
	static const int w = PIXELSIZE;
	static const int h = CHECKPOINTNUM;	
	static const int ratio = PREVIEWRATIO;		
	ofxCvColorImage	colorCurrentColorImage;
	ofxCvColorImage colorCurrentColorPreviewImage;
	int countActiveBalls;
	int countActiveBallsAnalyzedByCheckPoint;
	float averageSpeed;
private:
	ofxOscReceiver receiver;
	
	
};
